package ru.spb.osll.myfit.util;

import static org.junit.Assert.assertEquals;

import java.util.TreeMap;
import java.util.Vector;

import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.junit.Test;

import ru.spb.osll.myfit.common.Table;
import ru.spb.osll.myfit.common.TableCell;
import ru.spb.osll.myfit.server.CreateHelperServiceImpl;

public class ExampleEasyMockTest extends EasyMockSupport {
	public class DummyClass {
		private CreateHelperServiceImpl m_createHelperService;

		public DummyClass(CreateHelperServiceImpl fitService) {
			m_createHelperService = fitService;
		}

		public Table getTemplate(String name) throws Exception {
			m_createHelperService.loadTemplates();
//			m_fitService.savePage("", null);
			return m_createHelperService.getTemplate(name);
		}
	}

	public Table createTable() {
		Table table = new Table();
		Vector<TableCell> line = new Vector<TableCell>();
		line.add(new TableCell("write with cubetools"));
		table.addLine(line);
		return table;
	}

	@Test
	public void testGetTemplate() throws Exception {
	  CreateHelperServiceImpl fitService = createStrictMock(CreateHelperServiceImpl.class);
		DummyClass dummy = new DummyClass(fitService);
		Table table = createTable();

		EasyMock.expect(fitService.loadTemplates()).andReturn(new TreeMap<String, String>());
		EasyMock.expect(fitService.getTemplate("my template")).andReturn(table);

		replayAll();
		Table res = dummy.getTemplate("my template");
		verifyAll();
		assertEquals("write with cubetools", res.getData().get(0).get(0)
				.getText());
	}

}
